import Vue from 'vue';
import Component from '../messageBox';
const SuccessConstructor = Vue.extend(Component);
const type = 'success';
Component.name = 'messageBox-' + type;
const success = function (options) {
    return new Promise((resolve, reject) => {
        const {
            callback,
            ...rest
        } = options
        if (Vue.prototype.$isServer) return
        options = options || {}
        const id = 'message-' + type + 1;
        const instance = new SuccessConstructor({
            propsData: {
                ...rest
            }
        })
        instance.id = id
        instance.vm = instance.$mount()
        document.body.appendChild(instance.vm.$el)
        instance.vm.show = true;
        instance.vm.type = type;
        if (typeof callback === 'function') {
            callback(instance.vm);
        }
        instance.vm.$on('close', () => {
            reject();
            instance.vm.show = false;
        })
        instance.vm.$on('enter', () => {
            resolve();
            instance.vm.show = false;
        })
        return instance.vm
    })
}
export default success
